package com.qzsoft.zhjd.materiel.modules.materielstock.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.qzsoft.zhjd.common.annotation.ZhjdDataFilter;
import com.qzsoft.zhjd.common.components.BaseServiceComponent;
import com.qzsoft.zhjd.materiel.modules.materielstock.dto.MaterielStockListDto;
import com.qzsoft.zhjd.materiel.modules.materielstock.mapper.MaterielStockMapper;
import com.qzsoft.zhjd.materiel.modules.materielstock.service.MaterielStockService;

/**
 * @ClassName MaterielStockService
 * @Description 材料收发存统计分析业务接口实现
 * @author linhuawei
 * @since 2022-04-04
 */
@Service
public class MaterielStockServiceImpl implements MaterielStockService {

    @Autowired
    private MaterielStockMapper materielStockMapper;

    @Autowired
    private BaseServiceComponent baseServiceComponent;

    @Override
    @ZhjdDataFilter(tableAlias = "t1")
    public IPage<MaterielStockListDto> pageDto(Map<String, Object> params) {
        // 判断查询条件中是否有年份，如果有年份设置年份为累计年份
        // 如果有开始结束日期，获取开始或结束日期年份为累计年份
        if (ObjectUtils.isNotEmpty(params.get("year"))) {
            params.put("currentYear", params.get("year"));
        } else {
            Object temp = null == params.get("startDate") ? params.get("endDate") : null;
            if (null != temp) {
                String[] array = temp.toString().split("-");
                if (3 == array.length) {
                    params.put("currentYear", array[0]);
                }
            }
        }

        // 数据查询
        IPage<MaterielStockListDto> page = baseServiceComponent.getPage(params, MaterielStockListDto.class);
        return materielStockMapper.queryDto(page, params);
    }

}
